# -*- coding: utf-8 -*-
from seekfree import SERVO
from seekfree import GPIO

SERVO.help()                                    # 模块使用说明

servo = SERVO(50)                               # 初始化舵机接口 50Hz
# servo.enable()
# servo.disable()

pinpg3 = GPIO(0x63, 0, 1)                       # G3 输入 上拉

count = 0x1fff
n = 0
dir = 1
while 1:
    if dir == 1:
        n += 1
        if n >= 180:
            dir = 0
    else:
        n -= 1
        if n <= 0:
            dir = 1

    servo.angle(n)
    print(servo.pulse_width())
    while count:
        count -= 1
    count = 0x02ff
    if pinpg3.value() == 0:                     # 按下按键 G3
        print("Exti SERVO test program.\n")
        break                                   # 退出测试程序 （如果接下来要运行其他代码请先退出本测试程序）
